/* 
 * File:   TMessage.h
 * Author: JM
 *
 * Created on 13 maj 2010, 17:50
 */

#ifndef _TMESSAGE_H
#define	_TMESSAGE_H
#include <string>
#include <boost/smart_ptr.hpp>
#include "standardLindaHeaders.h"

enum TFieldType {
    ENumber, EString, EAny
};

class TAtomBase {
public:
    virtual ~TAtomBase(){ }

    inline const TFieldType getType() const {
        return type;
    }

    inline const boost::shared_ptr<TAtomBase> getNext() const {
        return next;
    }

    inline void setNext(const boost::shared_ptr<TAtomBase>& aNext) {
        next=aNext;
    }

protected:
    TFieldType type;

private:
    boost::shared_ptr<TAtomBase> next;
};

class TAtomNumeric : public TAtomBase{
public:
    TAtomNumeric(int aValue): value(aValue){
        type=ENumber;
    }
    
    inline const int getValue() const {
        return value;
    }

private:
    int value;
};

class TAtomString : public TAtomBase{
public:
    TAtomString(std::string aValue): value(aValue){
        type=EString;
    }
    
    inline std::string getValue() const {
        return value;
    }

private:
    std::string value;
};

/*
 * Class represents "krotka".
 * It contains a list of Atoms - it can be either string or numeric (int)
 * To read all Atoms from "krotka" U should get firstAtom and then try to
 * get next atom (TAtomBase::next) if ptr is valid
 */
class TMessage {
public:
    TMessage();
    virtual ~TMessage();

    void addAtom(std::string value);
    void addAtom(int value);
    std::string toString() const;

    inline const boost::shared_ptr<TAtomBase> getFirstAtom() const {
        return firstAtom;
    }

private:
    boost::shared_ptr<TAtomBase> firstAtom;
    boost::shared_ptr<TAtomBase> lastAtom;
};

#endif	/* _TMESSAGE_H */

